﻿namespace DslEditorPowerToy.Controls
{
    using System;
    using System.Drawing;
    using System.Drawing.Imaging;
    using System.Reflection;
    using System.Resources;
    using System.Windows.Forms;

    public abstract class HostedEditorDefinitionBase : IHostedEditorDefinition
    {
        private Guid _id = Guid.Empty;
        private System.Resources.ResourceManager _resourceManager;

        protected HostedEditorDefinitionBase(Guid editorId)
        {
            this._id = editorId;
        }

        private Bitmap EnsureImageIcon(Bitmap image)
        {
            if (image == null)
            {
                return image;
            }
            Rectangle rect = new Rectangle(0, 0, 0x10, 0x10);
            if ((rect.Right > image.Width) && (rect.Bottom > image.Height))
            {
                return image;
            }
            return image.Clone(rect, PixelFormat.Undefined);
        }

        protected Bitmap GetIconResource(string resourceId)
        {
            if (this.ResourceManager == null)
            {
                return null;
            }
            object obj2 = this.ResourceManager.GetObject(resourceId);
            if (obj2 == null)
            {
                return null;
            }
            Bitmap image = obj2 as Bitmap;
            if (image == null)
            {
                return null;
            }
            return this.EnsureImageIcon(image);
        }

        protected string GetStringResource(string resourceId)
        {
            if (this.ResourceManager == null)
            {
                return null;
            }
            return this.ResourceManager.GetString(resourceId);
        }

        public abstract string Caption { get; }

        public abstract System.Windows.Forms.Control Control { get; }

        public Guid Id
        {
            get
            {
                return this._id;
            }
        }

        public abstract Bitmap Image { get; }

        protected abstract Assembly ResourceAssembly { get; }

        protected abstract string ResourceFileName { get; }

        protected System.Resources.ResourceManager ResourceManager
        {
            get
            {
                if (this._resourceManager == null)
                {
                    this._resourceManager = new System.Resources.ResourceManager(this.ResourceFileName, this.ResourceAssembly);
                }
                return this._resourceManager;
            }
        }
    }
}

